package ar.edu.unq.tpi.construi.c1.tejeda.UI;

import java.util.Arrays;

import org.uqbar.arena.actions.MessageSend;
import org.uqbar.arena.layout.ColumnLayout;
import org.uqbar.arena.widgets.Button;
import org.uqbar.arena.widgets.Label;
import org.uqbar.arena.widgets.Panel;
import org.uqbar.arena.widgets.Selector;
import org.uqbar.arena.widgets.TextBox;
import org.uqbar.arena.windows.Dialog;
import org.uqbar.arena.windows.WindowOwner;
import org.uqbar.commons.model.Home;


import ar.edu.unq.tpi.constriu.c1.tejeda.Dominio.Agenda.Agenda;
import ar.edu.unq.tpi.constriu.c1.tejeda.Dominio.Agenda.Contact;

@SuppressWarnings("serial")
public abstract class AbstractContactDialog extends Dialog<Contact> {

	/**
	 * 
	 */
	
	private Home<Contact> home;

	public AbstractContactDialog(WindowOwner owner, Contact model) {
		super(owner, model);
		this.home = Agenda.getHome(Contact.class);
	}

	protected void createMainTemplate1(Panel mainPanel) {
		this.setTitle("ABM de contactos");
		super.createMainTemplate(mainPanel);
	}

	@Override
	protected abstract void executeTask();

	@Override
	protected void addActions(Panel actionsPanel) {
		new Button(actionsPanel).setCaption("Guardar").onClick(new MessageSend(this, ACCEPT)).setAsDefault().disableOnError();
		
		
	}

	protected void createMainTemplate(Panel mainPanel) {
		this.setTitle("Creación de contacto");
		super.createMainTemplate(mainPanel);
	}
	
	@Override
	protected void createFormPanel(Panel mainPanel) {
		// TODO Auto-generated method stub
		Panel form = new Panel(mainPanel);
		form.setLayout(new ColumnLayout(2));
		new Label(form).setText("Nombre");
		new TextBox(form).bindValueToProperty(Contact.NAME);
		new Label(form).setText("Phone number");
		new TextBox(form).bindValueToProperty(Contact.PHONENUMBER);
		new Label(form).setText("Mail");
		new TextBox(form).bindValueToProperty(Contact.MAIL);
		new Label(form).setText("Birth date");
		new TextBox(form).bindValueToProperty(Contact.BIRTHDATE);
		new Label(form).setText("City");
		new Selector(form).setContents(Arrays.asList(Contact.City.values()), "nombre").bindValueToProperty(Contact.CITY);
		new Label(form).setText("Observations");
		new TextBox(form).bindValueToProperty(Contact.OBSERVATIONS);
	}
	
	public Home<Contact> getHome() {
		return this.home;
	}
	
	

}
